﻿//验证码点击刷新
function ClickRemoveChangeCode() {
    var code = $("#imgCode").attr("src");
    $("#imgCode").attr("src", code + "1");
}
$(function () {
    $("#imgCode").tooltip();
})

//验证
$(".login").bootstrapValidator({
    message: '无效的值',
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh',
    },
    fields: {
        user: {
            message: '无效的数值',
            validators: {
                notempty: {
                    message: '用户名不能为空'
                }
            }
        },
        paw: {
            message: '无效的数值',
            validators: {
                notEmpty: {
                    message: '密码不能为空'
                }
            }
        },
        Code: {
            message: '无效的数值',
            validators: {
                notEmpty: {
                    message: '验证码不能为空'
                }
            }
        }
    }
})
//登陆方法
function login() {
    var bootstrapValidator = $(".login").data('bootstrapValidator');
    bootstrapValidator.validate();
    if (bootstrapValidator.isValid()) {
        var index = layer.load(1, { shade: [0.6, '#636363'] });
        $.post("/login/Index", { name: $("#user").val(), pwd: $("#Password").val(), code: $("#Code").val() }, function (data) {
            if (data.Code == "OK") {
                window.location.href = "/index/index";
            } else {
                layer.close(index);
                ClickRemoveChangeCode();
                layer.msg(data.Msg);
                
            }
        })
    }
}